package net.wesc.ac.server;

public class Model {
	static final double A0 = 0.509;
	static final double B0 = 3.291;
	static final double temp0 = 298.15;
	static int Zc;
	static int Za;
	static int Va;
	static int Vc;
	static int V;
	static double temp = temp0;
	static double A = A0;
	static double B = B0;
	  
	public static double DH(int tZa, int tZc, double x, double[] a, double ttemp){
		int a0 = 0;
		Zc = tZc;
		Za = tZa;
		Vc = Za;
		Va = Zc;
		V = Va+Vc;
		temp = ttemp;
		A = A0*Math.pow(temp0/temp, 1.5);
		B = B0*Math.pow(temp0/temp, 0.5);
		double I = 0.5*(Va*x*Math.pow(Za, 2)+Vc*x*Math.pow(Zc, 2)); //I ionic strength
	    return (-A*Math.sqrt(I))/(1+B*a[a0]*Math.sqrt(I));
	} //DH
	
	public static double HE(int tZa, int tZc, double x, double[] a, double ttemp){
		int a0 = 0;
		int a1 = 1;
		Zc = tZc;
		Za = tZa;
		Vc = Za;
		Va = Zc;
		V = Va+Vc;
		temp = ttemp;
		A = A0*Math.pow(temp0/temp, 1.5);
		B = B0*Math.pow(temp0/temp, 0.5);
		double I = 0.5*(Va*x*Math.pow(Za, 2)+Vc*x*Math.pow(Zc, 2)); //I ionic strength
		return (-A*Math.sqrt(I))/(1+B*a[a0]*Math.sqrt(I)) + a[a1]*I;
	} //HE
	
	public static double RS(int tZa, int tZc, double x, double aw,double[] a, double ttemp){
		int a0 = 0;
		int a1 = 1;
		Zc = tZc;
		Za = tZa;
		Vc = Za;
		Va = Zc;
		V = Va+Vc;
		temp = ttemp;
		A = A0*Math.pow(temp0/temp, 1.5);
		B = B0*Math.pow(temp0/temp, 0.5);
		double I = 0.5*(Va*x*Math.pow(Za, 2)+Vc*x*Math.pow(Zc, 2)); //I ionic strength
		return (-A*Math.abs(Za*Zc)*Math.sqrt(I))/(1+B*a[a0]*Math.sqrt(I))-a[a1]/V*Math.log10(aw)-Math.log10(1+0.018*x*(V-a[a1]));
	} //RS
	
	public static double GS(int tZa, int tZc, double x, double[] a, double ttemp){
		int a0 = 0;
		int a1 = 1;
		Zc = tZc;
		Za = tZa;
		Vc = Za;
		Va = Zc;
		V = Va+Vc;
		temp = ttemp;
		A = A0*Math.pow(temp0/temp, 1.5);
		double I = 0.5*(Va*x*Math.pow(Za, 2)+Vc*x*Math.pow(Zc, 2)); //I ionic strength
		return (-A*Math.abs(Za*Zc)*Math.sqrt(I))/(1+Math.sqrt(I)) + 2*Va/(Va+Vc)*a[a0]*Va*x + 2*Vc/(Va+Vc)*a[a1]*Vc*x;	
	}//GS

	public static double PP(int tZa, int tZc, double x, double[] a, double ttemp){
		int a0 = 0; //beta0
		int a1 = 1; //beta1
		int a2 = 2; //C psi
		temp = ttemp;
		A = A0*Math.pow(temp0/temp, 1.5);
		double b = 1.2;
		double alpha = 2.0;
		int Zc = 1;
		int Za = -1;
		int Va = 1;
		int Vc = 1;
		int V = Va+Vc;
		double I = x; //I ionic strength
		double fgamma = -(A/3)*(Math.sqrt(I)/(1+b*Math.sqrt(I))+(2/b)*Math.log(1+b*Math.sqrt(I)));
	    double Bgamma = 2*a[a0]+((2*a[a1])/(Math.pow(alpha, 2)*I))*(1-(1+alpha*Math.sqrt(I)-0.5*Math.pow(alpha, 2)*I)*Math.exp(-alpha*Math.sqrt(I)));
		return Math.abs(Zc*Za)*fgamma + x*(2*Va*Vc/V)*Bgamma + Math.pow(x, 2)*(2*Math.pow(Va*Vc, 1.5)/V)*a[a2];
	} //PP
}
